<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>ajax-demo</title>
</head>
<body>
    <p>
        <input type="button" value="发送" onclick="send();">
    </p>
    <script src="https://ajax.aspnetcdn.com/ajax/jquery/jquery-3.5.1.min.js" crossorigin="anonymous"></script>
    <script>
        function send() {
            $.post(
                "/community/alpha/ajax",
                {"name":"李四","age":20},
                function (data) { /*回调函数，服务器的数据返回给data，一个字符串*/
                    console.log(typeof(data));
                    console.log(data);

                    data = $.parseJSON(data); /*字符串转成js对象*/
                    console.log(typeof(data));
                    console.log(data.code);
                    console.log(data.msg);
                }
            );
        }
    </script>
</body>
</html>
